<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/3/25
 * Time: 20:03
 */

namespace front\modules\web\controllers;

use backfeed\services\CommentService;
use front\controllers\WebBaseController;
use goods\services\CollectionService;
use users\services\UserService;
use yii\helpers\ArrayHelper;

class MyController extends WebBaseController
{
    public $layout = 'main';

    public function actionIndex()
    {
        $data = [];
        $params['user_id'] = $this->getUserId();
        if($params['user_id'] == 0)
        {
            return $this->redirect('/web/user/login');
        }
        $data['comm'] = 0;
        $comm = CommentService::getCount($params);
        if($comm['code'] == 0){
            $data['comm'] = $comm['result']['count'];
        }
        //未读消息  暂时默认值 TODO
        $data['msg'] = 1;
        //当前用户收藏的商品数量
        $data['coll'] = CollectionService::getCollectionCount(null, $params['user_id']);
        $user = UserService::getUserInfo($params['user_id'], 1);
        $user = ArrayHelper::toArray($user['result']);
        $data['name'] = empty($user['username']) ? $user['mobile'] : $user['username'];
        $data['shop_id'] = $this->shop_id;
        return $this->render('my',['data'=>$data]);
    }
}